/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * vendedor.java
 *
 * Created on 09-mar-2012, 12:28:18
 */
package Examen.View;
import Examen.Controller.Conexion;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.sql.*;
import javax.swing.JTextField;
import java.lang.Object;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.print.*;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.MediaSizeName;
/**
 *
 * @author AkaMM
 */
public class vendedor extends javax.swing.JFrame implements Runnable{
    Conexion con,query;
    ResultSet rs;
    ResultSet rs2;
    public  int IDusuario;
    static int j=0; 
    static String aux3;
    static float total=0,invT=0;
   public static String id,cad;
   public static int rowCount, numfac;
   String hora,minutos,segundos,ampm;
    Calendar calendario;    
    Thread h1;
    int jj=0;

    /** Creates new form vendedor */
    public vendedor() {
        initComponents();
        h1 = new Thread(this);
            h1.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel33 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jTbcaducidad = new javax.swing.JTextField();
        jTbprecio = new javax.swing.JTextField();
        jTbexistencia = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jTproducto = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jTbdescripcion = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTbuscar = new javax.swing.JTable();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTbespecificaciones = new javax.swing.JTextArea();
        jScrollPane8 = new javax.swing.JScrollPane();
        jTbdescripcion2 = new javax.swing.JTextArea();
        jTID = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTbnombre1 = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        jTbnombre2 = new javax.swing.JTextField();
        jLabel34 = new javax.swing.JLabel();
        lbHora2 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel32 = new javax.swing.JLabel();
        lbHora3 = new javax.swing.JLabel();
        jTvnombre = new javax.swing.JTextField();
        jLabel43 = new javax.swing.JLabel();
        jBfactura = new javax.swing.JButton();
        jBventa = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        Tproductos = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        Tlista = new javax.swing.JTable();
        jBimprimir = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTtotal = new javax.swing.JTextField();
        jBquitar = new javax.swing.JButton();
        jLabel35 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel44 = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        jTinventario = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jTinvT = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLabel40 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Farmacia \"Las Lomas\" // Interfaz Vendedor");

        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel4.setOpaque(false);
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel33.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel33.setForeground(new java.awt.Color(204, 204, 204));
        jLabel33.setText("Busqueda por Descripcion:");
        jPanel4.add(jLabel33, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, -1, -1));

        jLabel18.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel18.setForeground(new java.awt.Color(204, 204, 204));
        jLabel18.setText("Existencia:");
        jPanel4.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 410, -1, -1));

        jLabel19.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel19.setForeground(new java.awt.Color(204, 204, 204));
        jLabel19.setText("Caducidad:");
        jPanel4.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 410, -1, -1));

        jLabel23.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel23.setForeground(new java.awt.Color(204, 204, 204));
        jLabel23.setText("Especificaciones:");
        jPanel4.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 450, -1, -1));

        jTbcaducidad.setEditable(false);
        jTbcaducidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTbcaducidadActionPerformed(evt);
            }
        });
        jPanel4.add(jTbcaducidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 410, 130, -1));

        jTbprecio.setEditable(false);
        jPanel4.add(jTbprecio, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 370, 110, -1));

        jTbexistencia.setEditable(false);
        jPanel4.add(jTbexistencia, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 410, 110, -1));

        jLabel25.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel25.setForeground(new java.awt.Color(204, 204, 204));
        jLabel25.setText("Precio:");
        jPanel4.add(jLabel25, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 370, -1, -1));

        jLabel36.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel36.setForeground(new java.awt.Color(204, 204, 204));
        jLabel36.setText("Nombre Producto:");
        jPanel4.add(jLabel36, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 370, -1, -1));

        jTproducto.setEditable(false);
        jPanel4.add(jTproducto, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 370, 220, -1));

        jLabel26.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel26.setForeground(new java.awt.Color(204, 204, 204));
        jLabel26.setText("Descripción:");
        jPanel4.add(jLabel26, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 450, -1, -1));

        jTbdescripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTbdescripcionKeyPressed(evt);
            }
        });
        jPanel4.add(jTbdescripcion, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 90, 220, -1));

        jTbuscar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTbuscar.setColumnSelectionAllowed(true);
        jTbuscar.getTableHeader().setReorderingAllowed(false);
        jTbuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTbuscarMouseClicked(evt);
            }
        });
        jTbuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTbuscarKeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(jTbuscar);

        jPanel4.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 120, 700, 200));

        jTbespecificaciones.setColumns(20);
        jTbespecificaciones.setEditable(false);
        jTbespecificaciones.setRows(5);
        jScrollPane7.setViewportView(jTbespecificaciones);

        jPanel4.add(jScrollPane7, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 450, 230, 170));

        jTbdescripcion2.setColumns(20);
        jTbdescripcion2.setEditable(false);
        jTbdescripcion2.setRows(5);
        jScrollPane8.setViewportView(jTbdescripcion2);

        jPanel4.add(jScrollPane8, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 450, 230, 170));

        jTID.setEditable(false);
        jTID.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jPanel4.add(jTID, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 30, 70, -1));

        jLabel12.setText("ID Admin:");
        jPanel4.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 30, -1, 20));

        jTbnombre1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTbnombre1KeyPressed(evt);
            }
        });
        jPanel4.add(jTbnombre1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 60, 220, -1));

        jLabel37.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Busqueda", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel4.add(jLabel37, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 800, 640));

        jTbnombre2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTbnombre2KeyPressed(evt);
            }
        });
        jPanel4.add(jTbnombre2, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 60, 220, -1));

        jLabel34.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel34.setForeground(new java.awt.Color(204, 204, 204));
        jLabel34.setText("Busqueda por Nombre:");
        jPanel4.add(jLabel34, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 60, -1, -1));

        lbHora2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        lbHora2.setText("jLabel42");
        lbHora2.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                lbHora2PropertyChange(evt);
            }
        });
        jPanel4.add(lbHora2, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 50, 160, -1));

        jPanel3.add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 850, 700));

        jLabel31.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fondo1.jpg"))); // NOI18N
        jLabel31.setMaximumSize(new java.awt.Dimension(500, 500));
        jLabel31.setMinimumSize(new java.awt.Dimension(500, 500));
        jLabel31.setName(""); // NOI18N
        jPanel3.add(jLabel31, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 950, 720));

        jTabbedPane1.addTab("Buscar", null, jPanel3, "Busqueda de Productos");

        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel32.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel32.setForeground(new java.awt.Color(204, 204, 204));
        jLabel32.setText("Nombre Producto:");
        jPanel2.add(jLabel32, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 60, -1, -1));

        lbHora3.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        lbHora3.setText("jLabel42");
        lbHora3.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                lbHora3PropertyChange(evt);
            }
        });
        jPanel2.add(lbHora3, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 20, 160, -1));

        jTvnombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTvnombreKeyPressed(evt);
            }
        });
        jPanel2.add(jTvnombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 60, 220, -1));

        jLabel43.setIcon(new javax.swing.ImageIcon(getClass().getResource("/logo11.png"))); // NOI18N
        jPanel2.add(jLabel43, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 260, 330, 110));

        jBfactura.setText("Factura");
        jBfactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBfacturaActionPerformed(evt);
            }
        });
        jPanel2.add(jBfactura, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 570, 120, 40));

        jBventa.setText("Agregar");
        jBventa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBventaActionPerformed(evt);
            }
        });
        jPanel2.add(jBventa, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 270, 120, 30));

        Tproductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        Tproductos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TproductosKeyPressed(evt);
            }
        });
        jScrollPane4.setViewportView(Tproductos);

        jPanel2.add(jScrollPane4, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 90, 760, 170));

        Tlista.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Precio", "Cantidad"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(Tlista);

        jPanel2.add(jScrollPane5, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 360, 760, 180));

        jBimprimir.setText("Imprimir");
        jBimprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBimprimirActionPerformed(evt);
            }
        });
        jPanel2.add(jBimprimir, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 570, 120, 40));

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel7.setText("Total:");
        jPanel2.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 300, -1, -1));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 0, 0));
        jLabel8.setText("$");
        jPanel2.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 280, 20, 60));

        jTtotal.setEditable(false);
        jTtotal.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jTtotal.setForeground(new java.awt.Color(255, 0, 0));
        jTtotal.setText("0.00");
        jPanel2.add(jTtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 280, 220, 60));

        jBquitar.setText("Limpiar");
        jBquitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBquitarActionPerformed(evt);
            }
        });
        jPanel2.add(jBquitar, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 570, 200, 30));

        jLabel35.setFont(new java.awt.Font("Tahoma", 0, 28)); // NOI18N
        jLabel35.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Venta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel2.add(jLabel35, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 10, 810, 630));

        jLabel30.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fondo1.jpg"))); // NOI18N
        jLabel30.setMaximumSize(new java.awt.Dimension(500, 500));
        jLabel30.setMinimumSize(new java.awt.Dimension(500, 500));
        jLabel30.setName(""); // NOI18N
        jPanel2.add(jLabel30, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 950, 720));

        jTabbedPane1.addTab("Venta", null, jPanel2, "Venta de Productos");

        jPanel6.setLayout(null);

        jLabel44.setIcon(new javax.swing.ImageIcon(getClass().getResource("/logo11.png"))); // NOI18N
        jPanel6.add(jLabel44);
        jLabel44.setBounds(250, 470, 314, 105);

        jTinventario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTinventario.getTableHeader().setReorderingAllowed(false);
        jTinventario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTinventarioMouseClicked(evt);
            }
        });
        jTinventario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTinventarioKeyPressed(evt);
            }
        });
        jScrollPane9.setViewportView(jTinventario);

        jPanel6.add(jScrollPane9);
        jScrollPane9.setBounds(75, 47, 700, 314);

        jButton3.setText("Imprimir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton3);
        jButton3.setBounds(230, 380, 120, 40);

        jTinvT.setEditable(false);
        jTinvT.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jTinvT.setForeground(new java.awt.Color(255, 0, 0));
        jTinvT.setText("0.00");
        jPanel6.add(jTinvT);
        jTinvT.setBounds(550, 380, 180, 46);

        jButton2.setText("Ventas del Día");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton2);
        jButton2.setBounds(370, 380, 120, 40);

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(255, 0, 0));
        jLabel16.setText("$");
        jPanel6.add(jLabel16);
        jLabel16.setBounds(530, 380, 17, 40);

        jLabel39.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel6.add(jLabel39);
        jLabel39.setBounds(30, 20, 800, 446);

        jLabel40.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fondo1.jpg"))); // NOI18N
        jLabel40.setMaximumSize(new java.awt.Dimension(500, 500));
        jLabel40.setMinimumSize(new java.awt.Dimension(500, 500));
        jLabel40.setName(""); // NOI18N
        jPanel6.add(jLabel40);
        jLabel40.setBounds(0, 0, 1139, 1050);

        jTabbedPane1.addTab("Inventario", jPanel6);

        jMenu3.setText("Modificar");

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Contraseña");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        jMenu2.setText("Info");

        jMenuItem2.setText("Acerca de...");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        jMenu4.setText("Salir");

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Cerrar Sesion");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Salir");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem4);

        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 884, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 726, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jTbcaducidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTbcaducidadActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTbcaducidadActionPerformed

private void jTbdescripcionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbdescripcionKeyPressed
//int evento=evt.getKeyCode();
//       
//        if(evento==10 ){
//             if (jTbnombre.getText().equals(""))
//        {
//
//            JOptionPane.showMessageDialog(null, "Escriba lo que desea buscar antes de presionar el boton.");
//
//        }
//
//        else
//
//        {
    
    
    try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                }
        
        String nom= jTbdescripcion.getText();
        String sql ="SELECT * FROM productos WHERE descripcion LIKE '%"+nom+"%'";
        rs = con.Consulta(sql);
        
        if(rs==null)
            JOptionPane.showMessageDialog(null, "No se encontro: "+jTbdescripcion.getText()+" en la base de datos.");
        
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTbuscar.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
        while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
          }
          buscar.addRow(fila);
 }
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
 
        
    
            
           
}//GEN-LAST:event_jTbdescripcionKeyPressed

private void jTbuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTbuscarMouseClicked
int Opcion=this.jTbuscar.getSelectedRow();
        //muestra el no. de renglon
       // JOptionPane.showMessageDialog(rootPane,Opcion);
        id =  jTbuscar.getValueAt(Opcion,0).toString();
        this.jTproducto.setText(this.jTbuscar.getValueAt(Opcion, 1).toString());
        this.jTbprecio.setText(this.jTbuscar.getValueAt(Opcion, 2).toString());
        this.jTbcaducidad.setText(this.jTbuscar.getValueAt(Opcion, 3).toString());
        this.jTbexistencia.setText(this.jTbuscar.getValueAt(Opcion, 4).toString());
        this.jTbdescripcion2.setText(this.jTbuscar.getValueAt(Opcion, 5).toString());
        this.jTbespecificaciones.setText(this.jTbuscar.getValueAt(Opcion, 6).toString());
           
}//GEN-LAST:event_jTbuscarMouseClicked

private void jTbnombre1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbnombre1KeyPressed
try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                }
        
        String nom= jTbnombre1.getText();
        String sql ="SELECT * FROM productos WHERE nombre_producto LIKE '%"+nom+"%'";
        rs = con.Consulta(sql);
        
        if(rs==null)
            JOptionPane.showMessageDialog(null, "No se encontro: "+jTbnombre1.getText()+" en la base de datos.");
        
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTbuscar.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
        while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
          }
          buscar.addRow(fila);
 }
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }// TODO add your handling code here:
}//GEN-LAST:event_jTbnombre1KeyPressed

private void jTvnombreKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTvnombreKeyPressed
//int evento=evt.getKeyCode();
       
//        if(evento==10 ){
//             if (jTvnombre.getText().equals(""))
//        {
//
//            JOptionPane.showMessageDialog(null, "Escriba lo que desea buscar antes de presionar el boton.");
//
//        }
//
//        else
//
//        {
//    
    
    try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                }
        
        String nom= jTvnombre.getText();
        String sql ="SELECT * FROM productos WHERE nombre_producto LIKE '"+nom+"%' AND existencia > 0";
        rs = con.Consulta(sql);
        
        if(rs==null)
            JOptionPane.showMessageDialog(null, "No se encontro: "+jTvnombre.getText()+" en la base de datos.");
        
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.Tproductos.setModel(buscar);
        
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        int y=0;
        while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
       
          }
          buscar.addRow(fila);
          for(int l=0;l<7;l++)
         buscar.isCellEditable(y, l);
         y++;
 }
 
        
 
         
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
 
        
    
            
//            }
}//GEN-LAST:event_jTvnombreKeyPressed

private void jBfacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBfacturaActionPerformed

    
   if (j==0)
        {

            JOptionPane.showMessageDialog(null, "No hay ningun elemento  en la Tabla de Venta");

        }

        else
    {
            try {
                factura Fac = new factura();
                rowCount = Tlista.getRowCount();
                numfac=1;
               rs = con.Consulta("SELECT * FROM `facturas`");
                while (rs.next()){
                
                    numfac++;
                
                }
                Fac.setNum(numfac);
                
                //int aux = Tlista.
                JTable t;
                t=Fac.getTabla();
                for(int k=0;k<j;k++)
                {
                    t.setValueAt(Tlista.getValueAt(k, 0), k, 0);
                    t.setValueAt(Tlista.getValueAt(k, 1), k, 1);
                    t.setValueAt(Tlista.getValueAt(k, 2), k, 2);
                }
                Fac.setTabla(t);
                Fac.setTotal(jTtotal.getText());
                Fac.setVisible(true);
            } catch (SQLException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            }
    
    
    }
}//GEN-LAST:event_jBfacturaActionPerformed

private void jBventaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBventaActionPerformed
//DefaultTableModel modelo = new DefaultTableModel();
//        this.Tlista.setModel(modelo);

    
    DefaultTableModel modelo = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};

    int aux = Tproductos.getSelectedRow();
    if (aux==-1)
        {

            JOptionPane.showMessageDialog(null, "No se a seleccionado nada de la tabla.");

        }

        else
    {

   
        
    
            
            String nombre = Tproductos.getValueAt(aux, 1).toString();
            String precio = Tproductos.getValueAt(aux, 2).toString();
         
        String aux2 = precio;
        float tot = Float.parseFloat(aux2);
        String cant = JOptionPane.showInputDialog("Cantidad: ");
        float cantidad = Float.parseFloat(cant);
        tot=tot*cantidad;
        total=tot+total;
        String aux4 = String.valueOf(total);
        jTtotal.setText(aux4);
        DefaultTableModel temp = (DefaultTableModel) 
                Tlista.getModel();
        Object nuevo[]= {temp.getRowCount()+1,"",""};
        temp.addRow(nuevo);
        
           Tlista.setValueAt(nombre, j, 0);
           Tlista.setValueAt(precio, j, 1);
           Tlista.setValueAt(cant, j, 2);
           j++;//Aumenta el contador

        
        }
}//GEN-LAST:event_jBventaActionPerformed

private void jBimprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBimprimirActionPerformed

    String existe = null;
    int e;
        String ID = null;
        String ticket;
    if (j==0)
        {

            JOptionPane.showMessageDialog(null, "No hay ningun elemento  en la Tabla de Venta");

        }

        else
    {
        
        try {
                //se crea la conexion y las consultas
                con = new Conexion();
                String pro[] = new String[100],p;
                String pro2[] = new String[100];
                int to[] = new int[100];
                float prec[] = new float[100];
                Object ex = null,precio=null;
                Object pros=null;
                
                // se crea la sentecia sql y se ejecuta para hacer la modificacion
                for (int i=0; i<j; i++) {
                     
                     pros = Tlista.getValueAt(i, 0);
                     pro[i] = objectToString(pros);
                     p=objectToString(Tlista.getValueAt(i, 1));
                     prec[i]= Float.parseFloat(p);
                     ex=  Tlista.getValueAt(i, 2);
                     String xe = objectToString(ex);
                     to[i] = Integer.parseInt(xe);
                   
                     String sqlc = "SELECT * FROM productos WHERE nombre_producto = '"+pro[i]+"'";
                    // System.out.println("antes");
                     rs = con.Consulta(sqlc);
                    // System.out.println("despues");
                     while(rs.next()){
                         ID = rs.getString(1);
                         existe = rs.getString(5);
                     
                     }
                    
                     e = Integer.parseInt(existe);
                    // Float k = Float.parseFloat(ex[i]);
                    int t = e - to[i];
                   
                    String modifica = "UPDATE  `productos` SET  `existencia` = "+t+" WHERE `id_producto` ="+ID+"";
                    con.ejecutar(modifica); 
                    
                }
//////                FileOutputStream os = null;
//////                try {
//////                    os = new FileOutputStream("ticket.txt");
//////                } catch (FileNotFoundException ex1) {
//////                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex1);
//////                }
//////                  PrintStream ps = new PrintStream(os);
                String iduser = jTID.getText();
                String user = "SELECT * FROM usuarios WHERE Id_usuario= '"+iduser+"'";
                String nombre = null,ap = null;
                rs = con.Consulta(user);
                while(rs.next()){
                         nombre = rs.getString(2);
                         ap = rs.getString(3);
                     }
                
                Date fecha = new Date();
                String t=jTtotal.getText();
                float tota = Float.parseFloat(t);
                String cadena="    Farmacia 'Las Lomas'\nRFC: TOSO850220GN9\nBaltazar N. 4  \nSan Antonio Coaxomulco, Tlaxcala\nFecha: "+fecha+"\n\nCant.\tProducto\tPrecio\n";
                String cade="";
                for (int i=0;i<j;i++){
                
                    pro2[i]=pro[i];
                    if(pro[i].length()<=8)
                        pro[i]=pro[i]+"     ";
                    if(pro[i].length()>15){
                        pro[i] = pro[i].substring(0, 15);
                    
                    }
                    cade = cade+""+to[i]+"\t"+pro[i]+"\t"+prec[i]*to[i]+"\n";
                
                }
                String efectivo = JOptionPane.showInputDialog(null, "Venta Realizada\nTotal a Cobrar: $"+t+"\nEfectivo Recibido: ");
                float efe = Float.parseFloat(efectivo);
                float cambio = efe - tota;
                 ticket = cadena+cade+"\n\tTotal: \t\t$"+jTtotal.getText()+"\n\tEfectivo: $"+efectivo+"\n\tCambio: $"+cambio+"\n    Le atendio: "+nombre+" "+ap+"\n\n    CON EL CORAZON EN LAS MANOS\n    GRACIAS POR SU COMPRA.\n\n\n\n";
                
                        
                         
                
                
                
                //Cogemos el servicio de impresión por defecto (impresora por defecto)
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
//Le decimos el tipo de datos que vamos a enviar a la impresora
//Tipo: bytes Subtipo: autodetectado
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
//Creamos un trabajo de impresión
DocPrintJob pj = service.createPrintJob();
//Nuestro trabajo de impresión envía una cadena de texto
String ss=ticket;
byte[] bytes;
//Transformamos el texto a bytes que es lo que soporta la impresora
bytes=ss.getBytes();
//Creamos un documento (Como si fuese una hoja de Word para imprimir)
Doc doc=new SimpleDoc(bytes,flavor,null);

//Obligado coger la excepción PrintException
  //Mandamos a impremir el documento
  pj.print(doc, null);


                
                
//////                ps.println(ticket);
//////                  ps.close();
                System.out.println(ticket);
                 
                
               
               String id34=jTID.getText();
               ticket = "";
                //String venta = "INSERT INTO `ventas`(`total`, `id_usuario`) VALUES (,'"+t+"','"+id34+"')";
                String venta = "INSERT INTO  `negocio`.`ventas` (`id_ventas` ,`total` ,`fecha` ,`Id_usuario`)VALUES (NULL ,  '"+t+"', CURRENT_TIMESTAMP ,  '"+id34+"');";
                con.ejecutar(venta);
                for(int i=0;i<j;i++){
                    venta = "INSERT INTO `negocio`.`vendidos` (`id_vendido`, `producto`, `precio`, `cantidad`, `fecha`, `Id_usuario`) VALUES (NULL, '"+pro2[i]+"', '"+prec[i]+"', '"+to[i]+"', CURRENT_TIMESTAMP, '"+id34+"');";
                    con.ejecutar(venta);
                }
                JOptionPane.showMessageDialog(null, "Venta Realizada\n\nTotal a Cobrar: $"+t+"\nCambio: $"+cambio);
                total=0;
                jTtotal.setText("0.00");


                int x =Tlista.getRowCount()-1;
                    DefaultTableModel temp = (DefaultTableModel) Tlista.getModel();
                    while(x>=0){
                    temp.removeRow(x);
                    x--;
                 
                }
    
    
                j=0;


            } catch (PrintException ex1) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex1);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    
    // TODO add your handling code here:
}//GEN-LAST:event_jBimprimirActionPerformed

private void jBquitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBquitarActionPerformed

    total=0;
    jTtotal.setText("0.00");
    
    
    int x =Tlista.getRowCount()-1;
    System.out.println("filas: "+x);
    
    {
    try
    {
        DefaultTableModel temp = (DefaultTableModel) Tlista.getModel();
        while(x>=0){
        temp.removeRow(x);
        x--;
        }
        
    }
        catch(ArrayIndexOutOfBoundsException e){}
    }
    
    
    j=0;
    
}//GEN-LAST:event_jBquitarActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        JOptionPane.showMessageDialog(rootPane, "Realizado por:\n\n Abraham Moreno Meza \n Lizeth Toledo Leon\n\n 2012");
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jTbnombre2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbnombre2KeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_jTbnombre2KeyPressed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    if(JOptionPane.showConfirmDialog(rootPane, "Esta seguro de cerrar la sesion actual?","Cerrar sesión",1)==0){
        
        this.dispose();
        inicio ini = new inicio();
        Dimension pantall = Toolkit.getDefaultToolkit().getScreenSize();  
        //obtenemos el tamaño de la ventana  
        Dimension ventan = ini.getSize();  
        //para centrar la ventana lo hacemos con el siguiente calculo  
        ini.setLocation((pantall.width - ventan.width) / 2, (pantall.height - ventan.height) / 2);
        ini.setVisible(true);

    }
    
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        if(JOptionPane.showConfirmDialog(rootPane, "Estás seguro de cerrar el Sistema?","Cerrar Sistema",1)==0){
            System.exit(0);
        }
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void TproductosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TproductosKeyPressed
int evento=evt.getKeyCode();
       
        if(evento==10 ){
             if (jTvnombre.getText().equals(""))
        {

            JOptionPane.showMessageDialog(null, "Escriba lo que desea buscar antes de presionar el boton.");

        }
             else {
                 
                 
    
    DefaultTableModel modelo = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};

    int aux = Tproductos.getSelectedRow();
    if (aux==-1)
        {

            JOptionPane.showMessageDialog(null, "No se a seleccionado nada de la tabla.");

        }

        else
    {

   
        
    
            
            String nombre = Tproductos.getValueAt(aux, 1).toString();
            String precio = Tproductos.getValueAt(aux, 2).toString();
         
        String aux2 = precio;
        float tot = Float.parseFloat(aux2);
        String cant = JOptionPane.showInputDialog("Cantidad: ");
        
        float cantidad = Float.parseFloat(cant);
        tot=tot*cantidad;
        total=tot+total;
        String aux5 = String.valueOf(total);
        jTtotal.setText(aux5);
        DefaultTableModel temp = (DefaultTableModel) 
                Tlista.getModel();
        Object nuevo[]= {temp.getRowCount()+1,"",""};
        temp.addRow(nuevo);
        
           Tlista.setValueAt(nombre, j, 0);
           Tlista.setValueAt(precio, j, 1);
           Tlista.setValueAt(cant, j, 2);
           j++;//Aumenta el contador

        
        }
                 
             }
        
        
        }// TODO add your handling code here:
}//GEN-LAST:event_TproductosKeyPressed

private void jTinventarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTinventarioMouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jTinventarioMouseClicked

private void jTinventarioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTinventarioKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_jTinventarioKeyPressed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        String[] inv = new String[20000];
        int w = 0;
        jj=0;
try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                }
     
        
       
        String iduser=jTID.getText();
           String sql ="SELECT * FROM vendidos WHERE (cast(fecha as DATE)) = DATE(NOW()) AND Id_usuario = '"+iduser+"'";

            rs = con.Consulta(sql);
       
       
       
        
        
        
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTinventario.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
        while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
           inv[w] = rs.getString(3);
           String ka1 = rs.getString(4);
           int ka = Integer.parseInt(ka1);
            Float auxo = Float.parseFloat(inv[w]);
            auxo = auxo * ka;
            invT = invT + auxo;                    
            w++;
            jj++;
          for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
          }
          buscar.addRow(fila);
 }
//        rs.next();
//        while(rs.next()){
//            
//        }
        
        jTinvT.setText(""+invT);
        System.out.println(invT);
        invT = 0;
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed

private void jTbuscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbuscarKeyPressed
int evento=evt.getKeyCode();
       
        if(evento==10 ){
    //DefaultTableModel modelo = new DefaultTableModel();
//        this.Tlista.setModel(modelo);

    
    DefaultTableModel modelo = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};

    int aux = jTbuscar.getSelectedRow();
    if (aux==-1)
        {

            JOptionPane.showMessageDialog(null, "No se a seleccionado nada de la tabla.");

        }

        else
    {

   
        
    
            
            String nombre = jTbuscar.getValueAt(aux, 1).toString();
            String precio = jTbuscar.getValueAt(aux, 2).toString();
         
        String aux2 = precio;
        float tot = Float.parseFloat(aux2);
        String cant = JOptionPane.showInputDialog("Cantidad: ");
        
        float cantidad = Float.parseFloat(cant);
        tot=tot*cantidad;
        total=tot+total;
        String aux3 = String.valueOf(total);
        jTtotal.setText(aux3);
        DefaultTableModel temp = (DefaultTableModel) 
                Tlista.getModel();
        Object nuevo[]= {temp.getRowCount()+1,"",""};
        temp.addRow(nuevo);
        
           Tlista.setValueAt(nombre, j, 0);
           Tlista.setValueAt(precio, j, 1);
           Tlista.setValueAt(cant, j, 2);
           j++;//Aumenta el contador
                              
    }
    
        }// TODO add your handling code here:
}//GEN-LAST:event_jTbuscarKeyPressed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed

    modificar mod = new modificar();
    mod.id = IDusuario;
    System.out.println("id para modificar: "+mod.id);
    mod.setVisible(true);
    
    
    
    
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void lbHora2PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_lbHora2PropertyChange
// TODO add your handling code here:
}//GEN-LAST:event_lbHora2PropertyChange

private void lbHora3PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_lbHora3PropertyChange
// TODO add your handling code here:
}//GEN-LAST:event_lbHora3PropertyChange

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    Object producto,canti,prec,idd;
    String cadenita = "",iid;
        String ss;
        String impresion;
    
                
    if(JOptionPane.showConfirmDialog(rootPane, "Desea imprimir el Inventario del día?","Imprimir Inventario",1)==0){
            try {
                con = new Conexion();
               // int selectedIndex = jCuser.getSelectedIndex();
                
                idd= jTinventario.getValueAt(0,5);
                
                String user = "SELECT * FROM usuarios WHERE Id_usuario= '"+idd+"'";
                        String nombre = null,ap = null;
                        rs = con.Consulta(user);
                        while(rs.next()){
                                 nombre = rs.getString(2);
                                 ap = rs.getString(3);
                             }
                
                    Date fecha = new Date();
                for(int x=0;x<jj;x++){
                
                   producto = jTinventario.getValueAt(x, 1);
                   String pro = objectToString(producto);
                    prec = jTinventario.getValueAt(x,2);
        //            String pre = objectToString(prec);
                    canti = jTinventario.getValueAt(x,3);
        //            String c = objectToString(canti);
                    
                    if(pro.length()<=8)
                        pro=pro+"     ";
                    if(pro.length()>15)
                        pro = pro.substring(0, 15);
                                
                    cadenita = cadenita+""+pro+"\t"+canti+"\t"+prec+"\n";
                   
                }
                 String cadena="    Farmacia 'Las Lomas'\nRFC: TOSO850220GN9\nBaltazar N. 4  \nSan Antonio Coaxomulco, Tlaxcala\nFecha: "+fecha+"\n\nProducto.\tCant.\tPrecio\n";
                 impresion = cadena+cadenita+"\nTotal: \t\t$"+jTinvT.getText()+"\n\n    Inventario de: "+nombre+" "+ap+"\n\n    CON EL CORAZON EN LAS MANOS.\n\n\n\n";
                  System.out.println(impresion);
                  
                
                
                
                PrintService service = PrintServiceLookup.lookupDefaultPrintService();
//Le decimos el tipo de datos que vamos a enviar a la impresora
//Tipo: bytes Subtipo: autodetectado
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
                //DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
//Creamos un trabajo de impresión
DocPrintJob pj = service.createPrintJob();
//Nuestro trabajo de impresión envía una cadena de texto
 ss=new String(impresion);
 
 //Font fuente = new Font("Arial", Font.PLAIN, 8);
 
byte[] bytes;
//Transformamos el texto a bytes que es lo que soporta la impresora
bytes=ss.getBytes();

//Creamos un documento (Como si fuese una hoja de Word para imprimir)
Doc doc=new SimpleDoc(bytes,flavor,null);



//Obligado coger la excepción PrintException
  //Mandamos a impremir el documento
  pj.print(doc, null);
               
                cadenita="";
            } catch (PrintException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            }
        
    }
    
    
    
    
    
    
}//GEN-LAST:event_jButton3ActionPerformed

public void setId(String id){
        String id2 = id;
    jTID.setText(id);
  
}
public void getT(String cad){
    aux3 = cad;
    System.out.println(aux3);
}

public void setT(String cad){
        String aux2 = cad;

}

public String getId(){
    cad = jTID.getText();
    return cad;
}

public int getFactura(){
        return rowCount;
}

public int getNumFac(){
        return numfac;
}

public String objectToString(Object o) {
        String st;
        st = (String) o;
        return st;
    }
public void calcula () {        
    Calendar calendario1 = new GregorianCalendar();
    Date fechaHoraActual = new Date();


    calendario1.setTime(fechaHoraActual);
    ampm = calendario1.get(Calendar.AM_PM)==Calendar.AM?"AM":"PM";

    if(ampm.equals("PM")){
         int h = calendario1.get(Calendar.HOUR_OF_DAY);
         hora = h>9?""+h:"0"+h;
    }else{
         hora = calendario1.get(Calendar.HOUR_OF_DAY)>9?""+calendario1.get(Calendar.HOUR_OF_DAY):"0"+calendario1.get(Calendar.HOUR_OF_DAY);            
    }
    minutos = calendario1.get(Calendar.MINUTE)>9?""+calendario1.get(Calendar.MINUTE):"0"+calendario1.get(Calendar.MINUTE);
    segundos = calendario1.get(Calendar.SECOND)>9?""+calendario1.get(Calendar.SECOND):"0"+calendario1.get(Calendar.SECOND); 
}
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(vendedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new vendedor().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Tlista;
    private javax.swing.JTable Tproductos;
    private javax.swing.JButton jBfactura;
    private javax.swing.JButton jBimprimir;
    private javax.swing.JButton jBquitar;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jBventa;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTextField jTID;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTbcaducidad;
    private javax.swing.JTextField jTbdescripcion;
    private javax.swing.JTextArea jTbdescripcion2;
    private javax.swing.JTextArea jTbespecificaciones;
    private javax.swing.JTextField jTbexistencia;
    private javax.swing.JTextField jTbnombre1;
    private javax.swing.JTextField jTbnombre2;
    private javax.swing.JTextField jTbprecio;
    private javax.swing.JTable jTbuscar;
    private javax.swing.JTextField jTinvT;
    private javax.swing.JTable jTinventario;
    private javax.swing.JTextField jTproducto;
    private javax.swing.JTextField jTtotal;
    private javax.swing.JTextField jTvnombre;
    private javax.swing.JLabel lbHora2;
    private javax.swing.JLabel lbHora3;
    // End of variables declaration//GEN-END:variables

    public void run() {
        Thread ct = Thread.currentThread();
         while(ct == h1) {   
          calcula();
          lbHora2.setText(hora + ":" + minutos + ":" + segundos + " "+ampm);
          lbHora3.setText(hora + ":" + minutos + ":" + segundos + " "+ampm);
          try {
           Thread.sleep(1000);
          }catch(InterruptedException e) {}
         }
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
